package org.fnzn.factory;

import org.fnzn.bean.LrdUser;
import org.fnzn.service.LoginService;
import org.fnzn.service.LrdOrgService;
import org.fnzn.web.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.fnzn.bean.LrdOrg;
import org.fnzn.bean.vo.User;
import org.fnzn.util.SpringUtil;

@Service
@DependsOn("springUtil")
@Transactional(readOnly = true)
public class UserFactory implements IUser{
	@Autowired
    private LoginService loginService;
    @Autowired
    private LrdOrgService lrdOrgService;
    @Autowired
	private UserService userService;

    public static IUser me() {
        return SpringUtil.getBean(IUser.class);
    }

    @Override
    public User user(LrdUser lrdUser) {
    	User user = new User();
		user.setCorpCD(lrdUser.getCorpCd());
		user.setUser_id(lrdUser.getUserId());
		user.setUserName(lrdUser.getUserName());						
		user.setSex(lrdUser.getSex());
		user.setIdNO(lrdUser.getIdNo());
		user.setTelNO(lrdUser.getTelNo());
		user.setEmail(lrdUser.getEmail());
		user.setJlFlag(lrdUser.getJlFlag());
		user.setOrgCD(lrdUser.getOrgCd());
		user.setDeptCD(lrdUser.getDeptCd());
		user.setManagerId(lrdUser.getManagerid());
		user.setTelNO(lrdUser.getTelNo());
		//查询机构名称
		LrdOrg lrdOrg = new LrdOrg();
		lrdOrg.setOrgCd(lrdUser.getOrgCd());
		lrdOrg.setCorpCd(lrdUser.getCorpCd());
//		LrdOrg  newLrdOrg = lrdOrgService.findOne(lrdOrg);
//		if(newLrdOrg!=null){
//			user.setOrgName(newLrdOrg.getOrgName());
//		}
		user.setROLE_CD(loginService.queryRole(lrdUser.getUserId()));
		user.setProjectId(lrdUser.getProjectId());
    	user.setPermissions(userService.getPermissionByUserId(lrdUser.getUserId()));
        return user;
    }

}
